/**
 * zmn渠道服务工程师-列表
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author xiangjunming
 * @since 2019/10/16 18:07
 */
layui.extend({
    zmnExportUtil: '{/}/static/js/zmn.excel.util'
}).define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate', 'zmnExportUtil'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    var laydate = layui.laydate;
    var zmnExportUtil = layui.zmnExportUtil;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-240',
        done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        }
    });
    laypage.render(zmnPage.laypageOptions(json));


    //【表格工具栏监听】
    table.on("toolbar(zmn-table)", function (obj) {
        if(obj.event == "del") {
            var ids = zmnPage.layTabldIds(obj, "id");
            if(ids.length === 0){ return layer.alert("请选择至少一条数据！"); }
            layer.confirm('确认移除服务商吗？', function() {
                zmnPage.ajaxSimple("/channel/sp/del", {ids: ids.join(',')}, 1500);
            });
            return;
        }

        if (obj.event == "selectWhiteList") {
            zmnLayUtil.openIframeCustom(layer, "/channel/sp/select.action?pageSize=50&pageNum=1&channelId="+json.channelId+"&type=2"+"&addFlag="+json.addFlag, {
                title: '新增白名单',
                area: ['60%', '60%']
            });
            return;
        }

        if (obj.event == "selectBlackList") {
            zmnLayUtil.openIframeCustom(layer, "/channel/sp/select.action?pageSize=50&pageNum=1&channelId=" + json.channelId + "&type=1" + "&addFlag=" + json.addFlag, {
                title: '新增黑名单',
                area: ['60%', '60%']
            });
            return;
        }

        //导出excel
        if (obj.event == 'CUSTOM_EXPORT') {
            zmnExportUtil.doExportExcel('zmn-table', '渠道服务商');
        }
    });

    //【表格右侧移除操作监听】
    table.on('tool(zmn-table)', function (obj) {

        var id = obj.data.id;
        if(obj.event == "del") {
            var ids = [];
            ids.push(id);
            layer.confirm('确认移除服务商吗？', function () {
                zmnPage.ajaxSimple("/channel/sp/del", {ids: ids.join(',')}, 1500);
            });
            return;
        }
    });

    //对外暴露的接口
    exports('channel_sp_list', {});
});